﻿angular.module('app.masterdata.user', [])
    .config(['$routeProvider', function ($routeProvider) {
        $routeProvider

        .when('/user/init', {
            templateUrl: 'app/masterdata/user/user-init.tpl.html',
            controller: 'userInitCtrl',
            resolve: {
                //首次加载第一页
                //                currentDeal: ['periodProxy', function (periodProxy) {
                //                    return periodProxy.searchInfo("Deal");
                //                } 
                //                ]
            }
        });
    } ])

    .controller('userInitCtrl', ['baseDataProxy', '$scope', 'permissionProxy', 'APPSETTING', 'collectorSignatureProxy', function (baseDataProxy, $scope,
        permissionProxy, APPSETTING, collectorSignatureProxy) {
        $scope.hidflg = false;

        permissionProxy.getCurrentUser("dummy", function (currUser) {
            if (!currUser.email) {
                alert("User's email account did not setup in intelligent OTC application.");
                $scope.canGrant = false;
            }
            $scope.email = currUser.email;
            $scope.canGrant = true;
        });

        $scope.changePassWordURL = APPSETTING.xcceleratorUrl + APPSETTING.changePassword;
        $scope.authPath = 'https://accounts.google.com/o/oauth2/auth?client_id=358145595498-1odj75ja10ujagebt3rsv743l8v4cbd2.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://mail.google.com&response_type=code';
        $scope.grant = function () {
            baseDataProxy.initialUser($scope.authCode, $scope.email, function (res) {
                alert('Permisson grant successed.');
            }, function (errMsg) {
                alert(errMsg);
            });
        }
        //加载collectorSingature
        collectorSignatureProxy.getCollectortSign("signature", function(collect) {        
                    $scope.collector = collect;         
        });
        //保存签名
        $scope.saveAutograph = function () {
            var ss = [];
            ss.push($scope.collector.signature);
           // var ss = encodeURIComponent($scope.collector.signature);
            collectorSignatureProxy.addOrUpdateCollect(ss, function (res) { alert(res); }, function () { alert("Update Failed"); });
        }

         //$scope.hidflg=true;
        baseDataProxy.getAuthentication(function (auth) {
            $scope.hidflg = auth;
        });
       
    } ]);